home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c++,comp.lang.c,comp.os.ms-windows.programmer.misc
- Subject: Re: fastest code
- Date: 10 Apr 1996 12:39:19 -0700
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4kh2p7INNkcq@keats.ugrad.cs.ubc.ca>
- References: <316112A2.7D37@public.sta.net.cn> <4kgbmj$j3j@solutions.solon.com> <4kghs7$250@news1.mnsinc.com> <4kgu7g$n9a@solutions.solon.com>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <4kgu7g$n9a@solutions.solon.com>,
- Peter Seebach <seebs@solon.com> wrote:
- >In article <4kghs7$250@news1.mnsinc.com>,
- >Szu-Wen Huang <huang@mnsinc.com> wrote:
- >>Peter Seebach (seebs@solutions.solon.com) wrote:
- >>: In article <1996Apr10.110121.6784@friend.kastle.com>,
- >>: Richard Krehbiel <rich@kastle.com> wrote:
- >>: >Oliver Hellwig <hellwig@rahul.net> wrote:
- >>: >> for (i=0; i<16; i++)
- >>: >> prom[i] = prom[i+i];
- >
- >>: HUH? the code as written has a clear effect, which is to shove all of
- >>: the elements of an array over one. It certainly is an optimizer bug.
- >
- >>: Read the code carefully; the 2nd reference to prom[] uses a different
- >>: index into the array. This is not a meaningless statement.
- >
- >>*You* read closely. The second index is "i+i". ;) Okay, so it's a
- >>typo, but one who says "read carefully" is expected to. Cheers.
- >
- >Okay, so the code becomes undefined when i becomes 8.
-
- No it actually does not. The prom array is declared to be 32 elements wide (I
- checked the code yesterday, the precise name is something like SA_prom), so
- prom[16] is well defined, as is prom[30]. The purpose of the code is to
- pack together array elements with even indices in an array of 32 elements;
- the loop is correct.
-
- What happens is that these 32 bytes are read from a hardware register and
- buffered. The code that reads them detects if they come in equivalent pairs and
- sets a flag called ``wordlength'' accordingly. If they are in pairs, they have
- to be squished, and the offending network card has to be sent a message to stop
- doing that (according to my primitive understanding of the code).
-
- Secondly, volatile is not going to help. prom[] is not an lvalue representing a
- memory mapped I/O region, or any storage that can unexpectedly change between
- sequence points, but a perfectly ordinary auto variable.
-
- >And does nothing when i is 0.
- >
- >But the intervening few cases would be expected to produce
- >assignments.
- >
- >I still think eliminating the assignments is a bug, and that "volatile"
- >should not have any effect, but I'll grant that it's far
- >from the only problem.
-
- Precisely. Volatile should have no effect here. The values of the array are
- subsequently depended on by other code, so eliminating the values is incorrect.
-
- The compiler would have to be extremely smart to eliminate the ``compression''
- loop and then split the subsequent code into two cases based on whether the
- loop was or was not supposed to have happened (this depends on a single
- variable ``wordlength'' that is set to either 1 or 2). But the original poster
- said that the compiler kept the loop anyway, just eliminated the assignments,
- and it's doubtful that Watcom, or any other compiler, would do this sort of
- optimization.
- --
-
-